<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        code: "",
        name: "",
        ip: "",
        port: null,
        status: 1,
        stationid: null,
        number: "",
        note: ""
    }),
    statusSelect: [],
    stationSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const statusSelect = ref(props.statusSelect);
const stationSelect = ref(props.stationSelect);

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="编码" prop="code">
          <el-input
            v-model="newFormInline.code"
            clearable
            placeholder="请输入编码"
          />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.name')" prop="name">
                    <el-input v-model="newFormInline.name" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.ipAddress')" prop="ip">
                    <el-input v-model="newFormInline.ip" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.communicationPort')" prop="port">
                    <el-input-number v-model="newFormInline.port" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.warehouseDoorStatus')" prop="status">
                    <el-select v-model="newFormInline.status" style="width:100%">
                        <!-- <el-option v-for="item in statusSelect" :key="item.value" :label="item.label"
                            :value="item.value" /> -->
                        <el-option :label="t('door.enable')" :value="1" />
                        <el-option :label="t('door.disable')" :value="2" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.relatedSites')" prop="stationid">
                    <el-select v-model="newFormInline.stationid" style="width:100%">
                        <el-option v-for="item in stationSelect" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('door.deviceNumber')" prop="number">
                    <el-input v-model="newFormInline.number" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('door.remarks')" prop="note">
                    <el-input v-model="newFormInline.note" clearable type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
